package com.qfedu.fmmall.controller;

import com.qfedu.fmmall.common.status.ResStatus;
import com.qfedu.fmmall.common.vo.ResultVO;
import com.qfedu.fmmall.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : yanBin
 * @date :2021/12/3 10:24
 */

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理",value = "提供用户的登录和注册接口")
@CrossOrigin
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation("用户登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String",name = "username",value = "用户登录账号",required = true),
            @ApiImplicitParam(dataType = "String",name = "password",value = "密码",required = false)})
    @GetMapping("/login")
    public ResultVO login(String username, String password){

        return userService.checkLogin(username, password);
    }
    @ApiOperation("用户注册接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String",name = "username",value = "用户登录账号",required = true),
            @ApiImplicitParam(dataType = "String",name = "password",value = "密码",required = true)})
    @PostMapping("/register")
    public ResultVO register(String username, String password){
        return userService.userRegistration(username,password);
    }

    @ApiOperation("校验token是否过期接口")
    @GetMapping("/check")
    public ResultVO userTokenchck(@RequestHeader("token") String token){
        return new ResultVO(ResStatus.OK.getCode(),"success",null);
    }
}
